<?php
	$key = isset($key) ? (int) $key : 0;
	$name = isset($name) ? $name : '';
	$pair = isset($pair) ? $pair : new stdClass();
	$type = isset($type) ? $type : 'M';
	$object_id = isset($object_id) ? $object_id : 0;
	$object_type = isset($object_type) ? $object_type : '';
	$delete_pair = isset($delete_pair) ? $delete_pair : true;
	$suffix = isset($suffix) ? $suffix : '';
?>

<input type="hidden" name="<?php echo $name ?>_image_data<?php echo $suffix ?>[<?php echo $key ?>][pair_id]" value="<?php echo isset($pair->pair_id) ? $pair->pair_id : '' ?>" class="cm-image-field" />
<input type="hidden" name="<?php echo $name ?>_image_data<?php echo $suffix ?>[<?php echo $key ?>][type]" value="<?php echo $type ?>" class="cm-image-field" />
<input type="hidden" name="<?php echo $name ?>_image_data<?php echo $suffix ?>[<?php echo $key ?>][object_id]" value="<?php echo $object_id ?>" class="cm-image-field" />

<div id="box_attach_images_<?php echo $name . '_' . $key ?>">
	<div class="clear">
		<?php if ( $delete_pair && (isset($pair) && isset($pair->pair_id)) ) : ?>
		<div class="float-right">
			<?php echo CHtml::link(t('Delete Image pair'), array('/image/delete/', 'pair_id' => $pair->pair_id, 'object_type' => $object_type), array('rev' => 'box_attach_images_'.$name.'_'.$key, 'class' => 'cm-confirm cm-ajax delete', 'name' => 'delete_image_pair')) ?>
		</div>
		<?php endif; ?>
		<?php if ( empty($hide_field_name) || !$hide_field_name ): ?>
		<p>
			<span class="field-name"><?php echo isset($icon_title) ? $icon_title : t('Image') ?></span>
			<span class="small-note"></span>
			<span class="field-name">:</span>
		</p>
		<?php endif; ?>

		<div class="float-left image">
			<?php echo $this->renderPartial('//common/image', array(
				'pair' => $pair,
				'object_type' => $object_type,
				'width' => 140,
				'height' => 140,
			)); ?>
			<?php if ( isset($pair->image_id) ) : ?>
			<p>
				<?php echo CHtml::link(t('Delete image'), array('/image/deleteImage', 'pair_id' => $pair->pair_id, 'image_id' => $pair->image_id, 'object_type' => $object_type), array('class' => 'cm-confirm cm-ajax delete', 'name' => 'delete_image')); ?>
			</p>
			<?php endif; ?>
		</div>

		<div class="float-left attach-images-alt">
			<?php $this->renderPartial('//common/fileuploader', array(
				'var_name' => "{$name}_image_icon{$suffix}[$key]",
				'image_name' => $name,
			)); ?>
			<label for="alt_icon_<?php echo $name . '_' . $key ?>">Ghi chú:</label>
			<input type="text" class="input-text cm-image-field" id="alt_icon_<?php echo $name . '_' . $key ?>" name="<?php echo $name ?>_image_data<?php echo $suffix ?>[<?php echo $key ?>][image_alt]" value="<?php echo isset($pair->image->alt) ? $pair->image->alt : '' ?>" />
		</div>
	</div>
</div>